{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "pA3VXX52Tec7"
      },
      "source": [
        "# **Imagga**"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "zuM3s1Xq8BGc"
      },
      "outputs": [],
      "source": [
        "import requests"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "_nrtaR7jfHYJ"
      },
      "outputs": [],
      "source": [
        "\n",
        "api_key = ' '\n",
        "api_secret = ' '\n",
        "image_path = ' '"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "pitiijiLeYiS",
        "outputId": "f15c7016-77ec-4e0b-ffc7-1f6762468bcc"
      },
      "outputs": [
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "{'result': {'tags': [{'confidence': 100, 'tag': {'en': 'dog'}}, {'confidence': 99.888053894043, 'tag': {'en': 'canine'}}, {'confidence': 71.5936431884766, 'tag': {'en': 'pet'}}, {'confidence': 64.8093719482422, 'tag': {'en': 'boxer'}}, {'confidence': 56.2753715515137, 'tag': {'en': 'puppy'}}, {'confidence': 46.6206665039062, 'tag': {'en': 'cute'}}, {'confidence': 44.8576850891113, 'tag': {'en': 'domestic animal'}}, {'confidence': 41.5463523864746, 'tag': {'en': 'breed'}}, {'confidence': 37.1279678344727, 'tag': {'en': 'friend'}}, {'confidence': 32.5374336242676, 'tag': {'en': 'domestic'}}, {'confidence': 32.0056610107422, 'tag': {'en': 'purebred'}}, {'confidence': 31.3631286621094, 'tag': {'en': 'adorable'}}, {'confidence': 31.2565879821777, 'tag': {'en': 'bull mastiff'}}, {'confidence': 28.2988243103027, 'tag': {'en': 'pedigree'}}, {'confidence': 27.1761455535889, 'tag': {'en': 'bull'}}, {'confidence': 26.4616985321045, 'tag': {'en': 'doggy'}}, {'confidence': 25.3908081054688, 'tag': {'en': 'bulldog'}}, {'confidence': 22.9422950744629, 'tag': {'en': 'funny'}}, {'confidence': 21.575496673584, 'tag': {'en': 'leash'}}, {'confidence': 21.3454093933105, 'tag': {'en': 'portrait'}}, {'confidence': 20.8176689147949, 'tag': {'en': 'device'}}, {'confidence': 19.8645782470703, 'tag': {'en': 'brown'}}, {'confidence': 19.1723861694336, 'tag': {'en': 'pets'}}, {'confidence': 19.0619373321533, 'tag': {'en': 'nose'}}, {'confidence': 18.676097869873, 'tag': {'en': 'pup'}}, {'confidence': 18.4170818328857, 'tag': {'en': 'pug'}}, {'confidence': 17.6779689788818, 'tag': {'en': 'dogs'}}, {'confidence': 17.2566452026367, 'tag': {'en': 'collar'}}, {'confidence': 17.0957469940186, 'tag': {'en': 'restraint'}}, {'confidence': 16.6643924713135, 'tag': {'en': 'pedigreed'}}, {'confidence': 16.3117275238037, 'tag': {'en': 'sitting'}}, {'confidence': 15.8504953384399, 'tag': {'en': 'retriever'}}, {'confidence': 15.7172212600708, 'tag': {'en': 'wrinkle'}}, {'confidence': 15.7009353637695, 'tag': {'en': 'companion'}}, {'confidence': 14.9088268280029, 'tag': {'en': 'face'}}, {'confidence': 14.8528871536255, 'tag': {'en': 'fur'}}, {'confidence': 14.7694358825684, 'tag': {'en': 'obedient'}}, {'confidence': 14.4300346374512, 'tag': {'en': 'studio'}}, {'confidence': 13.6435308456421, 'tag': {'en': 'expression'}}, {'confidence': 12.059757232666, 'tag': {'en': 'play'}}, {'confidence': 11.99001121521, 'tag': {'en': 'looking'}}, {'confidence': 11.9546604156494, 'tag': {'en': 'hunting dog'}}, {'confidence': 11.8501462936401, 'tag': {'en': 'wrinkly'}}, {'confidence': 11.8492994308472, 'tag': {'en': 'sweet'}}, {'confidence': 11.4172315597534, 'tag': {'en': 'black'}}, {'confidence': 11.1099424362183, 'tag': {'en': 'animals'}}, {'confidence': 11.007420539856, 'tag': {'en': 'two'}}, {'confidence': 10.9386777877808, 'tag': {'en': 'harness'}}, {'confidence': 10.8669404983521, 'tag': {'en': 'mastiff'}}, {'confidence': 10.765079498291, 'tag': {'en': 'wrinkled'}}, {'confidence': 10.6067066192627, 'tag': {'en': 'sad'}}, {'confidence': 10.5057935714722, 'tag': {'en': 'look'}}, {'confidence': 10.473840713501, 'tag': {'en': 'fun'}}, {'confidence': 10.0733413696289, 'tag': {'en': 'head'}}, {'confidence': 9.85619926452637, 'tag': {'en': 'ugly'}}, {'confidence': 9.70899772644043, 'tag': {'en': 'little'}}, {'confidence': 9.65012073516846, 'tag': {'en': 'ears'}}, {'confidence': 9.57478046417236, 'tag': {'en': 'watch'}}, {'confidence': 9.40729141235352, 'tag': {'en': 'outside'}}, {'confidence': 8.84793186187744, 'tag': {'en': 'terrier'}}, {'confidence': 8.79454517364502, 'tag': {'en': 'muzzle'}}, {'confidence': 8.74377059936523, 'tag': {'en': 'tired'}}, {'confidence': 8.6741771697998, 'tag': {'en': 'furry'}}, {'confidence': 8.59211444854736, 'tag': {'en': 'rest'}}, {'confidence': 8.56786823272705, 'tag': {'en': 'resting'}}, {'confidence': 8.53564167022705, 'tag': {'en': 'down'}}, {'confidence': 8.50173473358154, 'tag': {'en': 'pooch'}}, {'confidence': 8.4190034866333, 'tag': {'en': 'hound'}}, {'confidence': 8.22844886779785, 'tag': {'en': 'friendly'}}, {'confidence': 8.20689487457275, 'tag': {'en': 'outdoors'}}, {'confidence': 7.98757934570312, 'tag': {'en': 'close'}}, {'confidence': 7.84685897827148, 'tag': {'en': 'overweight'}}, {'confidence': 7.81939649581909, 'tag': {'en': 'paw'}}, {'confidence': 7.77659177780151, 'tag': {'en': 'sleep'}}, {'confidence': 7.77619218826294, 'tag': {'en': 'guard'}}, {'confidence': 7.5606837272644, 'tag': {'en': 'playful'}}, {'confidence': 7.50579595565796, 'tag': {'en': 'mammal'}}, {'confidence': 7.4972562789917, 'tag': {'en': 'support'}}, {'confidence': 7.35531425476074, 'tag': {'en': 'sporting dog'}}, {'confidence': 7.09061050415039, 'tag': {'en': 'male'}}]}, 'status': {'text': '', 'type': 'success'}}\n"
          ]
        }
      ],
      "source": [
        "response = requests.post(\n",
        "    'https://api.imagga.com/v2/tags',\n",
        "    auth=(api_key, api_secret),\n",
        "    files={'image': open(image_path, 'rb')})\n",
        "result = response.json()\n",
        "print(response.json())"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "0xmq3aZDJK4v",
        "outputId": "3061c78c-dafc-46b8-e658-ef81cf17ede4"
      },
      "outputs": [
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "Object: Dog Confidence: 1.00000\n",
            "Object: Canine Confidence: 0.99888\n",
            "Object: Pet Confidence: 0.71594\n",
            "Object: Boxer Confidence: 0.64809\n",
            "Object: Puppy Confidence: 0.56275\n",
            "Object: Cute Confidence: 0.46621\n",
            "Object: Domestic animal Confidence: 0.44858\n",
            "Object: Breed Confidence: 0.41546\n",
            "Object: Friend Confidence: 0.37128\n",
            "Object: Domestic Confidence: 0.32537\n",
            "Object: Purebred Confidence: 0.32006\n",
            "Object: Adorable Confidence: 0.31363\n",
            "Object: Bull mastiff Confidence: 0.31257\n",
            "Object: Pedigree Confidence: 0.28299\n",
            "Object: Bull Confidence: 0.27176\n",
            "Object: Doggy Confidence: 0.26462\n",
            "Object: Bulldog Confidence: 0.25391\n",
            "Object: Funny Confidence: 0.22942\n",
            "Object: Leash Confidence: 0.21575\n",
            "Object: Portrait Confidence: 0.21345\n",
            "Object: Device Confidence: 0.20818\n",
            "Object: Brown Confidence: 0.19865\n",
            "Object: Pets Confidence: 0.19172\n",
            "Object: Nose Confidence: 0.19062\n",
            "Object: Pup Confidence: 0.18676\n",
            "Object: Pug Confidence: 0.18417\n",
            "Object: Dogs Confidence: 0.17678\n",
            "Object: Collar Confidence: 0.17257\n",
            "Object: Restraint Confidence: 0.17096\n",
            "Object: Pedigreed Confidence: 0.16664\n",
            "Object: Sitting Confidence: 0.16312\n",
            "Object: Retriever Confidence: 0.15850\n",
            "Object: Wrinkle Confidence: 0.15717\n",
            "Object: Companion Confidence: 0.15701\n",
            "Object: Face Confidence: 0.14909\n",
            "Object: Fur Confidence: 0.14853\n",
            "Object: Obedient Confidence: 0.14769\n",
            "Object: Studio Confidence: 0.14430\n",
            "Object: Expression Confidence: 0.13644\n",
            "Object: Play Confidence: 0.12060\n",
            "Object: Looking Confidence: 0.11990\n",
            "Object: Hunting dog Confidence: 0.11955\n",
            "Object: Wrinkly Confidence: 0.11850\n",
            "Object: Sweet Confidence: 0.11849\n",
            "Object: Black Confidence: 0.11417\n",
            "Object: Animals Confidence: 0.11110\n",
            "Object: Two Confidence: 0.11007\n",
            "Object: Harness Confidence: 0.10939\n",
            "Object: Mastiff Confidence: 0.10867\n",
            "Object: Wrinkled Confidence: 0.10765\n",
            "Object: Sad Confidence: 0.10607\n",
            "Object: Look Confidence: 0.10506\n",
            "Object: Fun Confidence: 0.10474\n",
            "Object: Head Confidence: 0.10073\n",
            "Object: Ugly Confidence: 0.09856\n",
            "Object: Little Confidence: 0.09709\n",
            "Object: Ears Confidence: 0.09650\n",
            "Object: Watch Confidence: 0.09575\n",
            "Object: Outside Confidence: 0.09407\n",
            "Object: Terrier Confidence: 0.08848\n",
            "Object: Muzzle Confidence: 0.08795\n",
            "Object: Tired Confidence: 0.08744\n",
            "Object: Furry Confidence: 0.08674\n",
            "Object: Rest Confidence: 0.08592\n",
            "Object: Resting Confidence: 0.08568\n",
            "Object: Down Confidence: 0.08536\n",
            "Object: Pooch Confidence: 0.08502\n",
            "Object: Hound Confidence: 0.08419\n",
            "Object: Friendly Confidence: 0.08228\n",
            "Object: Outdoors Confidence: 0.08207\n",
            "Object: Close Confidence: 0.07988\n",
            "Object: Overweight Confidence: 0.07847\n",
            "Object: Paw Confidence: 0.07819\n",
            "Object: Sleep Confidence: 0.07777\n",
            "Object: Guard Confidence: 0.07776\n",
            "Object: Playful Confidence: 0.07561\n",
            "Object: Mammal Confidence: 0.07506\n",
            "Object: Support Confidence: 0.07497\n",
            "Object: Sporting dog Confidence: 0.07355\n",
            "Object: Male Confidence: 0.07091\n"
          ]
        }
      ],
      "source": [
        "for item in result['result']['tags']:\n",
        "    tag = item['tag']['en']\n",
        "    confidence = item['confidence'] / 100\n",
        "    print(f\"Object: {tag.capitalize()} Confidence: {confidence:.5f}\")"
      ]
    }
  ],
  "metadata": {
    "colab": {
      "provenance": []
    },
    "kernelspec": {
      "display_name": "Python 3",
      "name": "python3"
    },
    "language_info": {
      "name": "python"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}
